package com.yima.baseproj.module.app.page;

import cn.hutool.core.map.MapUtil;
import com.yima.baseproj.module.app.lunbotu.AppLunbotuService;
import com.yima.baseproj.module.app.lunbotu.model.AppLunbotuSearchModel;
import com.yima.baseproj.module.app.tongzhi.AppTongzhiService;
import com.yima.baseproj.module.app.user.AppUserEntity;
import com.yima.baseproj.module.config.BaseController;
import com.yima.baseproj.security.annotation.SecurityIgnoreUrl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @Author 一码
 * @createDate 2023/4/1 09:00
 * @contact 1424529270@qq.com
 */
@Api(tags = "页面管理",value = "用于前端页面统一获取数据。接口路径通常为页面路径")
@RestController
@RequestMapping("/api/app/page")
public class AppPageController extends BaseController {

    @Resource
    private AppLunbotuService appLunbotuService;

    @Resource
    private AppTongzhiService appTongzhiService;

    @ApiOperation(value = "查询首页数据")
    @SecurityIgnoreUrl
    @GetMapping(value = "/index")
    public Object findIndex() {
        Map result = MapUtil.newHashMap();
        //轮播图
        AppLunbotuSearchModel searchVo = new AppLunbotuSearchModel();
        searchVo.setState(1);
        List<Map> lunbotuList = appLunbotuService.findByList(searchVo);
        result.put("lunbotuList",lunbotuList);
        //通知
        Map tongzhiData = appTongzhiService.findHomeShow();
        result.put("tongzhiData",tongzhiData);

        return result;
    }

    @ApiOperation(value = "查询我的数据")
    @GetMapping(value = "/me")
    public Object findMe() {
        Map result = MapUtil.newHashMap();

        AppUserEntity appUserEntity = getUserEntity();
        if(appUserEntity != null){
            result.put("userInfo",MapUtil.builder()
                    .put("headImg",appUserEntity.getHeadImg())
                    .put("phone",appUserEntity.getPhone())
                    .put("nickName",appUserEntity.getNickName())
                    .build());
        }

        return result;
    }
}